package com.zbvc.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zbvc.dao.BookDao;
import com.zbvc.dao.impl.BookDaoImpl;
import com.zbvc.entity.Book;

/**
 * 查询书籍信息
 */
@WebServlet(name = "selectBookInfo", urlPatterns = { "/selectBookInfo" })
public class SelectBookInfo extends HttpServlet {
	
	private BookDao bookDao= new BookDaoImpl();
	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SelectBookInfo() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		String tip = request.getParameter("tip");
		String name = request.getParameter("name");
		List<Book> bookData = bookDao.findLikeBooks(name);
		HttpSession session = request.getSession();
		session.setAttribute("bookData", bookData);
		if("1".equals(tip)) {
			// 管理员
			response.sendRedirect("/book-manager/admin/admin_book.jsp");
		}else {
			// 读者
			response.sendRedirect("/book-manager/select.jsp");
			
			
		}
		
	}

}
